package com.hm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hm.mapper.StudentMapper;
import com.hm.pojo.entity.Student;
import com.hm.pojo.vo.StudentVo;
import com.hm.service.StudentService;
import com.hm.util.Result;
import com.mysql.cj.x.protobuf.MysqlxDatatypes;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Objects;


@Service
public class StudentServiceImpl implements StudentService{

    @Resource
    private StudentMapper studentMapper;

    @Override
    public Result findByPage(Integer current, Integer pageSize, StudentVo studentVo) {
        //分页对象
        Page<Student> page=new Page<>(current,pageSize);
        //条件对象-- xml
        QueryWrapper<Student> wrapper=new QueryWrapper<>();
        //判断是否为空
        if (StringUtils.hasText(studentVo.getSid())){
            wrapper.eq("sid",studentVo.getSid());
        }
        if (StringUtils.hasText(studentVo.getSname())){
            wrapper.like("sname",studentVo.getSname());
        }
        if (StringUtils.hasText(studentVo.getAge())){
            wrapper.ge("age",studentVo.getAge());
        }
        IPage<Student> byPage = studentMapper.findByPage(page, wrapper);

        return new Result(200,"分页查询学生成功",byPage);
    }

    @Override
    public Result updateById(Student student) {
        return new Result(200,"修改学生成功",studentMapper.updateById(student));
    }


}
